//
//  M4ProDetailSecondCell.swift
//  M4
//
//  Created by YuChuang on 2024/8/19.
//

import UIKit
import ActiveLabel
import SDWebImage

class M4ProDetailSecondCell: M4BaseTableViewCell {
    
    @IBOutlet weak var M4ProDetailLogo: UIImageView!
    
    @IBOutlet weak var M4ProDetailName: UILabel!
    
    @IBOutlet weak var M4ProDetailIVA: UILabel!
    
    @IBOutlet weak var M4ProDetailRecibia: UILabel!
    
    @IBOutlet weak var M4ProDetailPaga: UILabel!
    
    @IBOutlet weak var M4ProDetailDate: UILabel!
    
    @IBOutlet weak var M4ProDetailBottomView: UIView!
    
    @IBOutlet weak var M4ProDetailViewHeight: NSLayoutConstraint!
    
    @IBOutlet weak var M4ProDetailCheckButton: UIButton!
    
    @IBOutlet weak var M4ProDetailPrivacy: ActiveLabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        let activeHandle = ActiveType.custom(pattern: "Aviso de Privacidad")
        M4ProDetailPrivacy.enabledTypes = [activeHandle]
        M4ProDetailPrivacy.text = "He leído y acepto Aviso de Privacidad"
        M4ProDetailPrivacy.customColor[activeHandle] = COLOR_00479D
        M4ProDetailPrivacy.handleCustomTap(for: activeHandle) { element in
            self.M4CellActionDelegate?.M4CellAction(M4IDAction(actionType: M4ProDetailStatusAction.M4DetailPrivacyAction.rawValue, actionData: element))
        }
        M4ProDetailCheckButton.isSelected = true
        if M4UserDataManager.m4UserShare.M4AuditAccount == 1 {
            M4ProDetailPrivacy.isHidden = true
            M4ProDetailCheckButton.isHidden = true
        }
        else {
            M4ProDetailPrivacy.isHidden = false
            M4ProDetailCheckButton.isHidden = false
        }
    }
    
    override func M4UpdateDataAndUI() {
        let data = data as? M4UserProductList
        M4ProDetailLogo.sd_setImage(with: URL(string: data?.PLn ?? ""))
        M4ProDetailName.text = data?.RExEuGxUWqg
        M4ProDetailIVA.text = "$\(M4String.M4BlankAmount(original: "\(data?.yLkjhs ?? 0)"))"
        M4ProDetailRecibia.text = "$\(M4String.M4BlankAmount(original: "\(data?.Owwq ?? 0)"))"
        M4ProDetailPaga.text = "$\(M4String.M4BlankAmount(original: "\(data?.VvgkL?[0].Kfd ?? 0)"))"
//        let time = (data?.VvgkL?[0].PdwH ?? 0) / 1000
//        let date = Date(timeIntervalSince1970: TimeInterval(time))
//        let formatter = DateFormatter()
//        formatter.dateFormat = "dd/MM/yyyy"
//        let dateString = formatter.string(from: date)
        M4ProDetailDate.text = data?.VvgkL?[0].KyjWYy ?? ""
        
    }

    @IBAction func M4ProDetailCheckCLICK(_ sender: UIButton) {
        sender.isSelected = !sender.isSelected
        M4CellActionDelegate?.M4CellAction(M4IDAction(actionType: M4ProDetailStatusAction.M4DetailCheckAction.rawValue, actionData: sender.isSelected))
        sender.M4EventUnavailable = false
    }
    
    
}
